﻿using System;
using System.Linq;
using K9Nano.IM.Models;
using WalkingTec.Mvvm.Core;

namespace K9Nano.IM.Areas.Chat.ViewModels.AccountVMs
{
    public class DemoVM : ChatLoginVM
    {
        public string Area { get; set; }

        protected override void InitVM()
        {
            var appName = "示例";
            var app = DC.Set<ChatApp>().FirstOrDefault(x => x.Name == appName);
            if (app == null)
            {
                app = new ChatApp
                {
                    Name = appName,
                    Secret = "secret",
                    CustomerInfoCallback = "http://localhost/chat/account/DemoCustomer",
                    CustomerOrderCallback = "http://localhost/chat/account/DemoOrder",
                    IsValid = true
                };
                DC.AddEntity(app);
                DC.SaveChanges();
            }

            AppId = app.ID;
            Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
            var format = GetFormatString();
            Sign = Utils.GetMD5String(FormatSalt(format, app.Secret));
        }

        protected override void ReInitVM()
        {

        }

        public override void Validate()
        {

        }
    }
}